package com.yuki.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yuki.api.annotation.LogType;
import com.yuki.api.annotation.SystemLog;
import com.yuki.api.annotation.UserLoginToken;
import com.yuki.api.common.CommonPage;
import com.yuki.api.common.CommonResult;
import com.yuki.api.model.UmsUserView;
import com.yuki.api.service.ITokenService;
import com.yuki.api.service.IUserService;
import com.yuki.api.service.IUserViewService;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: Yuki Tadayoshi
 * @time: 2021/4/2 9:17
 */
@RestController
@RequestMapping("/uv")
@CrossOrigin
public class UmsUVController {
    @Reference(
            version = "1.0.0",
            interfaceName = "com.yuki.api.service.IUserViewService",
            interfaceClass = IUserViewService.class,
            timeout = 120000
    )
    private IUserViewService service;

    @Reference(
            version = "1.0.0",
            interfaceName = "com.yuki.api.service.ITokenService",
            interfaceClass = ITokenService.class,
            timeout = 120000
    )
    private ITokenService tokenService;

    @ResponseBody
    @GetMapping("/type")
    @UserLoginToken
    public CommonResult<CommonPage<UmsUserView>> getUVType() throws Exception {
        CommonPage page = service.listTypeUV();
        return CommonResult.success(page);
    }

    @GetMapping("/list")
    @ResponseBody
    @UserLoginToken
    @SystemLog(description = "UserView统计数据管理", type = LogType.UMS_USER_VIEW_LIST)
    public CommonResult<CommonPage<UmsUserView>> getUVList(
            @RequestParam(value = "start", required = true) String start,
            @RequestParam(value = "end", required = true) String end,
            @RequestParam(value = "type", required = true) String type) {
        return CommonResult.success(service.listUV(start, end, type));
    }
}
